<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/yuwanzi.io/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/yuwanzi.io/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/yuwanzi.io/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/yuwanzi.io/images/logo.svg" color="#222">

<link rel="stylesheet" href="/yuwanzi.io/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.1/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"suyuhuan.gitee.io","root":"/yuwanzi.io/","images":"/yuwanzi.io/images","scheme":"Muse","version":"8.2.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"Suche...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}};
  </script>
<meta name="description" content="概述&amp;nbsp;&amp;nbsp;HBase是一个分布式的、面向列的开源数据库，该技术来源于 Fay Chang 所撰写的Google论文“Bigtable：一个结构化数据的分布式存储系统”。就像Bigtable利用了Google文件系统（File System）所提供的分布式数据存储一样，HBase在Hadoop之上提供了类似于Bigtable的能力。HBase是Apache的Hadoop项目的子项">
<meta property="og:type" content="article">
<meta property="og:title" content="Hadoop学习笔记(4)-HBase">
<meta property="og:url" content="https://suyuhuan.gitee.io/yuwanzi.io/2016/07/17/2016-07-17-Hadoop04-HBase/index.html">
<meta property="og:site_name" content="玉丸子 | Blog">
<meta property="og:description" content="概述&amp;nbsp;&amp;nbsp;HBase是一个分布式的、面向列的开源数据库，该技术来源于 Fay Chang 所撰写的Google论文“Bigtable：一个结构化数据的分布式存储系统”。就像Bigtable利用了Google文件系统（File System）所提供的分布式数据存储一样，HBase在Hadoop之上提供了类似于Bigtable的能力。HBase是Apache的Hadoop项目的子项">
<meta property="og:locale">
<meta property="og:image" content="http://ww1.sinaimg.cn/mw690/63503acbjw1f5wxvstywwj20dx03odg2.jpg">
<meta property="og:image" content="http://ww4.sinaimg.cn/mw690/63503acbjw1f5x1207zfmj20gr0atq4h.jpg">
<meta property="og:image" content="http://ww2.sinaimg.cn/mw690/63503acbjw1f5x2cuji5gj20k409ddho.jpg">
<meta property="article:published_time" content="2016-07-17T10:00:00.000Z">
<meta property="article:modified_time" content="2020-11-07T00:58:17.000Z">
<meta property="article:author" content="玉丸子">
<meta property="article:tag" content="Hadoop">
<meta property="article:tag" content="大数据">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://ww1.sinaimg.cn/mw690/63503acbjw1f5wxvstywwj20dx03odg2.jpg">


<link rel="canonical" href="https://suyuhuan.gitee.io/yuwanzi.io/2016/07/17/2016-07-17-Hadoop04-HBase/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh'
  };
</script>
<title>Hadoop学习笔记(4)-HBase | 玉丸子 | Blog</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/yuwanzi.io/atom.xml" title="玉丸子 | Blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Navigationsleiste an/ausschalten" role="button">
    </div>
  </div>

  <div class="site-meta">

    <a href="/yuwanzi.io/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">玉丸子 | Blog</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>







</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          Inhaltsverzeichnis
        </li>
        <li class="sidebar-nav-overview">
          Übersicht
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%A6%82%E8%BF%B0"><span class="nav-number">1.</span> <span class="nav-text">概述</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HBase%E7%9A%84%E7%89%B9%E7%82%B9"><span class="nav-number">2.</span> <span class="nav-text">HBase的特点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%A1%8C%E5%BC%8F%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%8E%E5%88%97%E5%BC%8F%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="nav-number">3.</span> <span class="nav-text">行式数据库与列式数据库的区别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HBase%E6%9E%B6%E6%9E%84"><span class="nav-number">4.</span> <span class="nav-text">HBase架构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HBase%E9%9B%86%E7%BE%A4%E6%90%AD%E5%BB%BA"><span class="nav-number">5.</span> <span class="nav-text">HBase集群搭建</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#hbase-env-sh"><span class="nav-number">5.1.</span> <span class="nav-text">hbase-env.sh</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#hbase-site-xml"><span class="nav-number">5.2.</span> <span class="nav-text">hbase-site.xml</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#regionservers"><span class="nav-number">5.3.</span> <span class="nav-text">regionservers</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HBase%E5%B8%B8%E7%94%A8Shell%E5%91%BD%E4%BB%A4"><span class="nav-number">6.</span> <span class="nav-text">HBase常用Shell命令</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">玉丸子</p>
  <div class="site-description" itemprop="description">这里是玉丸子的个人博客,与你一起发现更大的世界。</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/yuwanzi.io/archives">
          <span class="site-state-item-count">68</span>
          <span class="site-state-item-name">Artikel</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/yuwanzi.io/categories/">
        <span class="site-state-item-count">39</span>
        <span class="site-state-item-name">Kategorien</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/yuwanzi.io/tags/">
        <span class="site-state-item-count">46</span>
        <span class="site-state-item-name">schlagwörter</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh">
    <link itemprop="mainEntityOfPage" href="https://suyuhuan.gitee.io/yuwanzi.io/2016/07/17/2016-07-17-Hadoop04-HBase/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/yuwanzi.io/images/avatar.gif">
      <meta itemprop="name" content="玉丸子">
      <meta itemprop="description" content="这里是玉丸子的个人博客,与你一起发现更大的世界。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="玉丸子 | Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Hadoop学习笔记(4)-HBase
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Veröffentlicht am</span>

      <time title="Erstellt: 2016-07-17 18:00:00" itemprop="dateCreated datePublished" datetime="2016-07-17T18:00:00+08:00">2016-07-17</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Bearbeitet am</span>
        <time title="Geändert am: 2020-11-07 08:58:17" itemprop="dateModified" datetime="2020-11-07T08:58:17+08:00">2020-11-07</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">in</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/yuwanzi.io/categories/%E5%90%8E%E7%AB%AF/" itemprop="url" rel="index"><span itemprop="name">后端</span></a>
        </span>
          . 
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/yuwanzi.io/categories/%E5%90%8E%E7%AB%AF/%E5%A4%A7%E6%95%B0%E6%8D%AE/" itemprop="url" rel="index"><span itemprop="name">大数据</span></a>
        </span>
          . 
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/yuwanzi.io/categories/%E5%90%8E%E7%AB%AF/%E5%A4%A7%E6%95%B0%E6%8D%AE/Hadoop/" itemprop="url" rel="index"><span itemprop="name">Hadoop</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <p><img src="http://ww1.sinaimg.cn/mw690/63503acbjw1f5wxvstywwj20dx03odg2.jpg"></p>
<h3 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h3><p>&nbsp;&nbsp;HBase是一个分布式的、面向列的开源数据库，该技术来源于 Fay Chang 所撰写的Google论文“Bigtable：一个结构化数据的分布式存储系统”。就像Bigtable利用了Google文件系统（File System）所提供的分布式数据存储一样，HBase在Hadoop之上提供了类似于Bigtable的能力。HBase是Apache的Hadoop项目的子项目。HBase不同于一般的关系数据库，它是一个适合于非结构化数据存储的数据库。另一个不同的是HBase基于列的而不是基于行的模式。</p>
<p>&nbsp;&nbsp;与FUJITSU Cliq等商用大数据产品不同，HBase是Google Bigtable的开源实现，类似Google Bigtable利用GFS作为其文件存储系统，HBase利用Hadoop HDFS作为其文件存储系统；Google运行MapReduce来处理Bigtable中的海量数据，HBase同样利用Hadoop MapReduce来处理HBase中的海量数据；Google Bigtable利用 Chubby作为协同服务，HBase利用Zookeeper作为对应。</p>
<h3 id="HBase的特点"><a href="#HBase的特点" class="headerlink" title="HBase的特点"></a>HBase的特点</h3><ol>
<li>Hbase可以往数据里面insert，也可以update一些数据，但update的实际上也是insert，只是插入一个新的时间戳的一行。delete数据，也是insert，只是insert一行带有delete标记的一行。Hbase的所有操作都是追加插入操作。Hbase是一种日志集数据库。它的存储方式，像是日志文件一样。它是批量大量的往硬盘中写，通常都是以文件形式的读写。这个读写速度，取决于硬盘与机器之间的传输有多快。</li>
<li>Hbase中数据可以保存许多不同时间戳的版本（即同一数据可以复制许多不同的版本，准许数据冗余，也是优势）。数据按时间排序，因此Hbase特别适合寻找按照时间排序寻找Top n的场景。找出某个人最近浏览的消息，最近写的N篇博客，N种行为等等，因此Hbase在互联网应用非常多。</li>
<li>Hbase只有主键索引，因此在建模的时候会遇到了问题。例如，在一张表中，很多的列我都想做某种条件的查询。但却只能在主键上建快速查询。</li>
<li>Hbase是列式数据库,列式数据库的优势在于数据分析。</li>
<li>Hbase中的数据都是字符串，没有其他类型。</li>
</ol>
<h3 id="行式数据库与列式数据库的区别"><a href="#行式数据库与列式数据库的区别" class="headerlink" title="行式数据库与列式数据库的区别"></a>行式数据库与列式数据库的区别</h3><p> <strong>行式数据库</strong></p>
<p> &nbsp;&nbsp;以Oracle为例，数据文件的基本组成单位：块/页。块中数据是按照一行行写入的。这就存在一个问题，当我们要读一个块中的某些列的时候，不能只读这些列，必须把这个块整个的读入内存中，再把这些列的内容读出来。换句话就是：为了读表中的某些列，必须要把整个表的行全部读完，才能读到这些列。这就是行数据库最糟糕的地方。</p>
<p> <strong>列式数据库</strong> </p>
<p> &nbsp;&nbsp;列式数据库是以列作为元素存储的。同一个列的元素会挤在一个块。当要读某些列，只需要把相关的列块读到内存中，这样读的IO量就会少很多。通常，同一个列的数据元素通常格式都是相近的。这就意味着，当数据格式相近的时候，数据就可以做大幅度的压缩。所以，列式数据库在数据压缩方面有很大的优势，压缩不仅节省了存储空间，同时也节省了IO。（这一点，可利用在当数据达到百万、千万级别以后，数据查询之间的优化，提高性能，示场景而定）</p>
<h3 id="HBase架构"><a href="#HBase架构" class="headerlink" title="HBase架构"></a>HBase架构</h3><p><img src="http://ww4.sinaimg.cn/mw690/63503acbjw1f5x1207zfmj20gr0atq4h.jpg"></p>
<p>&nbsp;&nbsp;HBase采用Master/Slave架构搭建集群，它隶属于Hadoop生态系统，由以下类型节点组成：HMaster节点、HRegionServer节点、ZooKeeper集群，而在底层，它将数据存储于HDFS中，因而涉及到HDFS的NameNode、DataNode等节点。</p>
<p><strong>Zookeeper</strong></p>
<p>&nbsp;&nbsp;Zookeeper Quorum存储-ROOT-表地址、HMaster地址。HRegionServer把自己以Ephedral方式注册到Zookeeper中，HMaster随时感知各个HRegionServer的健康状况。</p>
<p><strong>HMaster</strong></p>
<p>&nbsp;&nbsp;HMaster没有单点问题,HBase中可以启动多个HMaster，通过Zookeeper的Master Election机制保证总有一个Master在运行。</p>
<p>&nbsp;&nbsp;HMaster主要负责Table和Region的管理工作</p>
<ol>
<li>实现DDL操作（Data Definition Language，namespace和table的增删改，column familiy的增删改等）。</li>
<li>管理HRegionServer的负载均衡，调整Region分布。</li>
<li>管理和分配HRegion，比如在HRegion split时分配新的HRegion；在HRegionServer退出时迁移其内的HRegion到其他HRegionServer上。</li>
<li>权限控制（ACL）。</li>
</ol>
<p><strong>HRegionServer</strong></p>
<p>&nbsp;&nbsp;HBase中最核心的模块，主要负责响应用户I/O请求，向HDFS文件系统中读写数据。</p>
<ol>
<li>存放和管理本地HRegion。</li>
<li>读写HDFS，管理Table中的数据。</li>
<li>Client直接通过HRegionServer读写数据（从HMaster中获取元数据，找到RowKey所在的HRegion/HRegionServer后）。</li>
</ol>
<p><strong>HRegion</strong></p>
<p><img src="http://ww2.sinaimg.cn/mw690/63503acbjw1f5x2cuji5gj20k409ddho.jpg"></p>
<p>&nbsp;&nbsp;HBase使用RowKey将表水平切割成多个HRegion，从HMaster的角度，每个HRegion都纪录了它的StartKey和EndKey（第一个HRegion的StartKey为空，最后一个HRegion的EndKey为空），由于RowKey是排序的，因而Client可以通过HMaster快速的定位每个RowKey在哪个HRegion中。HRegion由HMaster分配到相应的HRegionServer中，然后由HRegionServer负责HRegion的启动和管理，和Client的通信，负责数据的读(使用HDFS)。</p>
<h3 id="HBase集群搭建"><a href="#HBase集群搭建" class="headerlink" title="HBase集群搭建"></a>HBase集群搭建</h3><p>&nbsp;&nbsp;如果HDFS是HA集群,需要把HDFS的core-site.xml和hdfs-site.xml copy到conf下。</p>
<h4 id="hbase-env-sh"><a href="#hbase-env-sh" class="headerlink" title="hbase-env.sh"></a>hbase-env.sh</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;告诉hbase使用外部的zookeeper</span><br><span class="line">export HBASE_MANAGES_ZK&#x3D;false</span><br></pre></td></tr></table></figure>
<h4 id="hbase-site-xml"><a href="#hbase-site-xml" class="headerlink" title="hbase-site.xml"></a>hbase-site.xml</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&lt;configuration&gt;</span><br><span class="line">	&lt;!-- 指定hbase在HDFS上存储的路径 --&gt;</span><br><span class="line">    &lt;property&gt;</span><br><span class="line">        &lt;name&gt;hbase.rootdir&lt;&#x2F;name&gt;</span><br><span class="line">        &lt;value&gt;hdfs:&#x2F;&#x2F;ns1&#x2F;hbase&lt;&#x2F;value&gt;</span><br><span class="line">    &lt;&#x2F;property&gt;</span><br><span class="line">	&lt;!-- 指定hbase是分布式的 --&gt;</span><br><span class="line">    &lt;property&gt;</span><br><span class="line">        &lt;name&gt;hbase.cluster.distributed&lt;&#x2F;name&gt;</span><br><span class="line">        &lt;value&gt;true&lt;&#x2F;value&gt;</span><br><span class="line">    &lt;&#x2F;property&gt;</span><br><span class="line">	&lt;!-- 指定zk的地址，多个用“,”分割 --&gt;</span><br><span class="line">    &lt;property&gt;</span><br><span class="line">        &lt;name&gt;hbase.zookeeper.quorum&lt;&#x2F;name&gt;</span><br><span class="line">        &lt;value&gt;datanode01:2181,datanode02:2181,datanode03:2181&lt;&#x2F;value&gt;</span><br><span class="line">    &lt;&#x2F;property&gt;</span><br><span class="line">    &lt;property&gt;</span><br><span class="line">        &lt;name&gt;hbase.master.maxclockskew&lt;&#x2F;name&gt;</span><br><span class="line">        &lt;value&gt;180000&lt;&#x2F;value&gt;</span><br><span class="line">        &lt;description&gt;Time difference of regionserver from master&lt;&#x2F;description&gt;</span><br><span class="line"> 	&lt;&#x2F;property&gt;</span><br><span class="line">&lt;&#x2F;configuration&gt;</span><br></pre></td></tr></table></figure>
<h4 id="regionservers"><a href="#regionservers" class="headerlink" title="regionservers"></a>regionservers</h4><p>&nbsp;&nbsp;配置regionserver的节点,为了尽量实现数据本地化,可以与DataNode在同一个节点上。</p>
<h3 id="HBase常用Shell命令"><a href="#HBase常用Shell命令" class="headerlink" title="HBase常用Shell命令"></a>HBase常用Shell命令</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br></pre></td><td class="code"><pre><span class="line">进入hbase命令行</span><br><span class="line">.&#x2F;hbase shell</span><br><span class="line"></span><br><span class="line">显示hbase中的表</span><br><span class="line">list</span><br><span class="line"></span><br><span class="line">创建user表，包含info、data两个列族</span><br><span class="line">create &#39;user&#39;, &#39;info1&#39;, &#39;data1&#39;</span><br><span class="line">create &#39;user&#39;, &#123;NAME &#x3D;&gt; &#39;info&#39;, VERSIONS &#x3D;&gt; &#39;3&#39;&#125;</span><br><span class="line"></span><br><span class="line">向user表中插入信息，row key为rk0001，列族info中添加name列标示符，值为zhangsan</span><br><span class="line">put &#39;user&#39;, &#39;rk0001&#39;, &#39;info:name&#39;, &#39;zhangsan&#39;</span><br><span class="line"></span><br><span class="line">向user表中插入信息，row key为rk0001，列族info中添加gender列标示符，值为female</span><br><span class="line">put &#39;user&#39;, &#39;rk0001&#39;, &#39;info:gender&#39;, &#39;female&#39;</span><br><span class="line"></span><br><span class="line">向user表中插入信息，row key为rk0001，列族info中添加age列标示符，值为20</span><br><span class="line">put &#39;user&#39;, &#39;rk0001&#39;, &#39;info:age&#39;, 20</span><br><span class="line"></span><br><span class="line">向user表中插入信息，row key为rk0001，列族data中添加pic列标示符，值为picture</span><br><span class="line">put &#39;user&#39;, &#39;rk0001&#39;, &#39;data:pic&#39;, &#39;picture&#39;</span><br><span class="line"></span><br><span class="line">获取user表中row key为rk0001的所有信息</span><br><span class="line">get &#39;user&#39;, &#39;rk0001&#39;</span><br><span class="line"></span><br><span class="line">获取user表中row key为rk0001，info列族的所有信息</span><br><span class="line">get &#39;user&#39;, &#39;rk0001&#39;, &#39;info&#39;</span><br><span class="line"></span><br><span class="line">获取user表中row key为rk0001，info列族的name、age列标示符的信息</span><br><span class="line">get &#39;user&#39;, &#39;rk0001&#39;, &#39;info:name&#39;, &#39;info:age&#39;</span><br><span class="line"></span><br><span class="line">获取user表中row key为rk0001，info、data列族的信息</span><br><span class="line">get &#39;user&#39;, &#39;rk0001&#39;, &#39;info&#39;, &#39;data&#39;</span><br><span class="line">get &#39;user&#39;, &#39;rk0001&#39;, &#123;COLUMN &#x3D;&gt; [&#39;info&#39;, &#39;data&#39;]&#125;</span><br><span class="line"></span><br><span class="line">get &#39;user&#39;, &#39;rk0001&#39;, &#123;COLUMN &#x3D;&gt; [&#39;info:name&#39;, &#39;data:pic&#39;]&#125;</span><br><span class="line"></span><br><span class="line">获取user表中row key为rk0001，列族为info，版本号最新5个的信息</span><br><span class="line">get &#39;user&#39;, &#39;rk0001&#39;, &#123;COLUMN &#x3D;&gt; &#39;info&#39;, VERSIONS &#x3D;&gt; 2&#125;</span><br><span class="line">get &#39;user&#39;, &#39;rk0001&#39;, &#123;COLUMN &#x3D;&gt; &#39;info:name&#39;, VERSIONS &#x3D;&gt; 5&#125;</span><br><span class="line">get &#39;user&#39;, &#39;rk0001&#39;, &#123;COLUMN &#x3D;&gt; &#39;info:name&#39;, VERSIONS &#x3D;&gt; 5, TIMERANGE &#x3D;&gt; [1392368783980, 1392380169184]&#125;</span><br><span class="line"></span><br><span class="line">获取user表中row key为rk0001，cell的值为zhangsan的信息</span><br><span class="line">get &#39;people&#39;, &#39;rk0001&#39;, &#123;FILTER &#x3D;&gt; &quot;ValueFilter(&#x3D;, &#39;binary:图片&#39;)&quot;&#125;</span><br><span class="line"></span><br><span class="line">获取user表中row key为rk0001，列标示符中含有a的信息</span><br><span class="line">get &#39;people&#39;, &#39;rk0001&#39;, &#123;FILTER &#x3D;&gt; &quot;(QualifierFilter(&#x3D;,&#39;substring:a&#39;))&quot;&#125;</span><br><span class="line"></span><br><span class="line">put &#39;user&#39;, &#39;rk0002&#39;, &#39;info:name&#39;, &#39;fanbingbing&#39;</span><br><span class="line">put &#39;user&#39;, &#39;rk0002&#39;, &#39;info:gender&#39;, &#39;female&#39;</span><br><span class="line">put &#39;user&#39;, &#39;rk0002&#39;, &#39;info:nationality&#39;, &#39;中国&#39;</span><br><span class="line">get &#39;user&#39;, &#39;rk0002&#39;, &#123;FILTER &#x3D;&gt; &quot;ValueFilter(&#x3D;, &#39;binary:中国&#39;)&quot;&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">查询user表中的所有信息</span><br><span class="line">scan &#39;user&#39;</span><br><span class="line"></span><br><span class="line">查询user表中列族为info的信息</span><br><span class="line">scan &#39;user&#39;, &#123;COLUMNS &#x3D;&gt; &#39;info&#39;&#125;</span><br><span class="line">scan &#39;user&#39;, &#123;COLUMNS &#x3D;&gt; &#39;info&#39;, RAW &#x3D;&gt; true, VERSIONS &#x3D;&gt; 5&#125;</span><br><span class="line">scan &#39;persion&#39;, &#123;COLUMNS &#x3D;&gt; &#39;info&#39;, RAW &#x3D;&gt; true, VERSIONS &#x3D;&gt; 3&#125;</span><br><span class="line">查询user表中列族为info和data的信息</span><br><span class="line">scan &#39;user&#39;, &#123;COLUMNS &#x3D;&gt; [&#39;info&#39;, &#39;data&#39;]&#125;</span><br><span class="line">scan &#39;user&#39;, &#123;COLUMNS &#x3D;&gt; [&#39;info:name&#39;, &#39;data:pic&#39;]&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">查询user表中列族为info、列标示符为name的信息</span><br><span class="line">scan &#39;user&#39;, &#123;COLUMNS &#x3D;&gt; &#39;info:name&#39;&#125;</span><br><span class="line"></span><br><span class="line">查询user表中列族为info、列标示符为name的信息,并且版本最新的5个</span><br><span class="line">scan &#39;user&#39;, &#123;COLUMNS &#x3D;&gt; &#39;info:name&#39;, VERSIONS &#x3D;&gt; 5&#125;</span><br><span class="line"></span><br><span class="line">查询user表中列族为info和data且列标示符中含有a字符的信息</span><br><span class="line">scan &#39;user&#39;, &#123;COLUMNS &#x3D;&gt; [&#39;info&#39;, &#39;data&#39;], FILTER &#x3D;&gt; &quot;(QualifierFilter(&#x3D;,&#39;substring:a&#39;))&quot;&#125;</span><br><span class="line"></span><br><span class="line">查询user表中列族为info，rk范围是[rk0001, rk0003)的数据</span><br><span class="line">scan &#39;people&#39;, &#123;COLUMNS &#x3D;&gt; &#39;info&#39;, STARTROW &#x3D;&gt; &#39;rk0001&#39;, ENDROW &#x3D;&gt; &#39;rk0003&#39;&#125;</span><br><span class="line"></span><br><span class="line">查询user表中row key以rk字符开头的</span><br><span class="line">scan &#39;user&#39;,&#123;FILTER&#x3D;&gt;&quot;PrefixFilter(&#39;rk&#39;)&quot;&#125;</span><br><span class="line"></span><br><span class="line">查询user表中指定范围的数据</span><br><span class="line">scan &#39;user&#39;, &#123;TIMERANGE &#x3D;&gt; [1392368783980, 1392380169184]&#125;</span><br><span class="line"></span><br><span class="line">删除数据</span><br><span class="line">删除user表row key为rk0001，列标示符为info:name的数据</span><br><span class="line">delete &#39;people&#39;, &#39;rk0001&#39;, &#39;info:name&#39;</span><br><span class="line">删除user表row key为rk0001，列标示符为info:name，timestamp为1392383705316的数据</span><br><span class="line">delete &#39;user&#39;, &#39;rk0001&#39;, &#39;info:name&#39;, 1392383705316</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">清空user表中的数据</span><br><span class="line">truncate &#39;people&#39;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">修改表结构</span><br><span class="line">首先停用user表（新版本不用）</span><br><span class="line">disable &#39;user&#39;</span><br><span class="line"></span><br><span class="line">添加两个列族f1和f2</span><br><span class="line">alter &#39;people&#39;, NAME &#x3D;&gt; &#39;f1&#39;</span><br><span class="line">alter &#39;user&#39;, NAME &#x3D;&gt; &#39;f2&#39;</span><br><span class="line">启用表</span><br><span class="line">enable &#39;user&#39;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">###disable &#39;user&#39;(新版本不用)</span><br><span class="line">删除一个列族：</span><br><span class="line">alter &#39;user&#39;, NAME &#x3D;&gt; &#39;f1&#39;, METHOD &#x3D;&gt; &#39;delete&#39; 或 alter &#39;user&#39;, &#39;delete&#39; &#x3D;&gt; &#39;f1&#39;</span><br><span class="line"></span><br><span class="line">添加列族f1同时删除列族f2</span><br><span class="line">alter &#39;user&#39;, &#123;NAME &#x3D;&gt; &#39;f1&#39;&#125;, &#123;NAME &#x3D;&gt; &#39;f2&#39;, METHOD &#x3D;&gt; &#39;delete&#39;&#125;</span><br><span class="line"></span><br><span class="line">将user表的f1列族版本号改为5</span><br><span class="line">alter &#39;people&#39;, NAME &#x3D;&gt; &#39;info&#39;, VERSIONS &#x3D;&gt; 5</span><br><span class="line">启用表</span><br><span class="line">enable &#39;user&#39;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">删除表</span><br><span class="line">disable &#39;user&#39;</span><br><span class="line">drop &#39;user&#39;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">get &#39;person&#39;, &#39;rk0001&#39;, &#123;FILTER &#x3D;&gt; &quot;ValueFilter(&#x3D;, &#39;binary:中国&#39;)&quot;&#125;</span><br><span class="line">get &#39;person&#39;, &#39;rk0001&#39;, &#123;FILTER &#x3D;&gt; &quot;(QualifierFilter(&#x3D;,&#39;substring:a&#39;))&quot;&#125;</span><br><span class="line">scan &#39;person&#39;, &#123;COLUMNS &#x3D;&gt; &#39;info:name&#39;&#125;</span><br><span class="line">scan &#39;person&#39;, &#123;COLUMNS &#x3D;&gt; [&#39;info&#39;, &#39;data&#39;], FILTER &#x3D;&gt; &quot;(QualifierFilter(&#x3D;,&#39;substring:a&#39;))&quot;&#125;</span><br><span class="line">scan &#39;person&#39;, &#123;COLUMNS &#x3D;&gt; &#39;info&#39;, STARTROW &#x3D;&gt; &#39;rk0001&#39;, ENDROW &#x3D;&gt; &#39;rk0003&#39;&#125;</span><br><span class="line"></span><br><span class="line">scan &#39;person&#39;, &#123;COLUMNS &#x3D;&gt; &#39;info&#39;, STARTROW &#x3D;&gt; &#39;20140201&#39;, ENDROW &#x3D;&gt; &#39;20140301&#39;&#125;</span><br><span class="line">scan &#39;person&#39;, &#123;COLUMNS &#x3D;&gt; &#39;info:name&#39;, TIMERANGE &#x3D;&gt; [1395978233636, 1395987769587]&#125;</span><br><span class="line">delete &#39;person&#39;, &#39;rk0001&#39;, &#39;info:name&#39;</span><br><span class="line"></span><br><span class="line">alter &#39;person&#39;, NAME &#x3D;&gt; &#39;ffff&#39;</span><br><span class="line">alter &#39;person&#39;, NAME &#x3D;&gt; &#39;info&#39;, VERSIONS &#x3D;&gt; 10</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">get &#39;user&#39;, &#39;rk0002&#39;, &#123;COLUMN &#x3D;&gt; [&#39;info:name&#39;, &#39;data:pic&#39;]&#125;</span><br></pre></td></tr></table></figure>
    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/yuwanzi.io/tags/Hadoop/" rel="tag"># Hadoop</a>
              <a href="/yuwanzi.io/tags/%E5%A4%A7%E6%95%B0%E6%8D%AE/" rel="tag"># 大数据</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/yuwanzi.io/2016/07/15/2016-07-15-Hadoop03-HA/" rel="prev" title="Hadoop学习笔记(3)-HA高可用集群搭建">
                  <i class="fa fa-chevron-left"></i> Hadoop学习笔记(3)-HA高可用集群搭建
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/yuwanzi.io/2016/07/18/2016-07-18-Hadoop05-Hive/" rel="next" title="Hadoop学习笔记(5)-Hive">
                  Hadoop学习笔记(5)-Hive <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">玉丸子</span>
</div>
  <div class="powered-by">Erstellt mit  <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a>
  </div>

    </div>
  </footer>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/yuwanzi.io/js/utils.js"></script><script src="/yuwanzi.io/js/motion.js"></script><script src="/yuwanzi.io/js/schemes/muse.js"></script><script src="/yuwanzi.io/js/next-boot.js"></script>

  






  





</body>
</html>
